import type { ResData } from '@/types'
import type { MenuHandleTable, MenuTable } from '@/types/menu'
import { req } from '@/util/request'
import { deepCopy } from '@/util/token'

/* 查询菜单 */
export function getSysMenus(cdn?: MenuTable): ResData<MenuTable[]> {
  return req.get('/menu/all')
}

/* 添加菜单 */
export function addSysMenu(data: MenuTable): ResData<any> {
  return req.post('/menu/add', data)
}

/* 更新某个菜单 */
export function updateSysMenu(data: MenuTable): ResData<any> {
  return req.post('/menu/update', data)
}

/* 获取菜单上的所有按钮 */
export function getSysMenuHandles(mid: number): ResData<MenuHandleTable[]> {
  return req.get('/menu/get/handles', {
    params: {
      mid
    }
  })
}

/* 更新菜单上的按钮 */
export function updateSysMenuHandles(mid: number, data: MenuHandleTable[]): ResData<any> {
  data = deepCopy(data)
  return req.post('/menu/handles/update', {
    mid,
    data
  })
}

/* 删除菜单 */

export function delMenu(mids: number[]): ResData<any> {
  return req.post('/menu/delete', mids)
}
